package app

import (
	"gin-app/app/common/request"
	"gin-app/app/common/response"
	"gin-app/app/services"
	"github.com/gin-gonic/gin"
)

// 新建零售负责人
func CreateRetailPersonInCharge(c *gin.Context) {
	var form request.CreateRetailPersonInCharge
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	if err, personInCharge := services.PersonInChargeService.CreateRetailPersonInCharge(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, personInCharge)
	}
}

// 获取零售负责人列表
func GetRetailPersonInChargeList(c *gin.Context) {
	if err, personInCharge := services.PersonInChargeService.GetRetailPersonInChargeList(); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, personInCharge)
	}
}

// 删除零售负责人
func DeleteRetailPersonInCharge(c *gin.Context) {
	var form request.DeleteRetailPersonInCharge
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	if err := services.PersonInChargeService.DeleteRetailPersonInCharge(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, "OK")
	}
}

// 编辑零售负责人
func EditorRetailPersonInCharge(c *gin.Context) {
	var form request.EditorRetailPersonInCharge
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	if err, personInCharge := services.PersonInChargeService.EditorRetailPersonInCharge(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, personInCharge)
	}
}

// 新建水源负责人
func CreateWaterSourcePersonInCharge(c *gin.Context) {
	var form request.CreateWaterSourcePersonInCharge
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	if err, personInCharge := services.PersonInChargeService.CreateWaterSourcePersonInCharge(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, personInCharge)
	}
}

// 获取水源负责人列表
func GetWaterSourcePersonInChargeList(c *gin.Context) {
	if err, personInCharge := services.PersonInChargeService.GetWaterSourcePersonInChargeList(); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, personInCharge)
	}
}

// 删除水源负责人
func DeleteWaterSourcePersonInCharge(c *gin.Context) {
	var form request.DeleteWaterSourcePersonInCharge
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	if err := services.PersonInChargeService.DeleteWaterSourcePersonInCharge(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, "OK")
	}
}

// 编辑水源负责人
func EditorWaterSourcePersonInCharge(c *gin.Context) {
	var form request.EditorWaterSourcePersonInCharge
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	if err, personInCharge := services.PersonInChargeService.EditorWaterSourcePersonInCharge(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, personInCharge)
	}
}
